//
//  MapInitializeDemoViewController.m
//  FMDemoBaseMap
//
//  Created by fengmap on 16/10/17.
//  Copyright © 2016年 fengmap. All rights reserved.
//
//  地图初始化设置
//  简介：设置地图中心点，旋转、倾斜角度，显示级别；

#import "MapInitializeDemoViewController.h"
#import "FMMapKit.h"

@interface MapInitializeDemoViewController () <FMKMapViewDelegate>
{
    FMKMapView *_mapView;
    // 地图中心点
    FMKGeoCoord _mapCenter;
}

@end

@implementation MapInitializeDemoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 离线地图加载
    NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"jlai-cyds-museum02" ofType:@"fmap"];
    _mapView = [[FMKMapView alloc] initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) path:dataPath delegate:self];
    [self.view addSubview:_mapView];
    
    NSString *themePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"jlai-cyds-museum02/jlai-cyds-museum02.theme"];
    [_mapView setThemeWithLocalPath:themePath];

    // 设置地图中心点
   _mapCenter = FMKGeoCoordMake(1, FMKMapPointMake((_mapView.map.info.minX+_mapView.map.info.maxX)/2, (_mapView.map.info.minY+_mapView.map.info.maxY)/2));
    
    //_mapCenter = FMKGeoCoordMake(1, FMKMapPointMake(120, 500));
    [_mapView moveToViewCenterFromMapPoint:_mapCenter.mapPoint animated:NO];

    // 设置地图旋转角度
    _mapView.map.mapStatus.rotateAngle = 60;
    // 设置地图倾斜角度
    _mapView.map.mapStatus.inclineAngle = 45;
    // 设置地图显示级别
    [_mapView.map setZoomLevel:20 animated:NO];
    
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 140, [UIScreen mainScreen].bounds.size.width, 140)];
    [self.view addSubview:textView];
    textView.backgroundColor = [UIColor clearColor];
    textView.editable = NO;
    textView.font = [UIFont systemFontOfSize:15];
    NSString *text = [NSString stringWithFormat:@"地图初始状态设置为：\n 地图中心点：楼层(groupID)：%d\n 坐标(mapPoint)：(%.2f, %.2f)\n 旋转角度(rotateAngle)：%.2f\n 倾斜角度(inclineAngle)：%.2f\n 显示级别：%d", _mapCenter.groupID, _mapCenter.mapPoint.x, _mapCenter.mapPoint.y, _mapView.map.mapStatus.rotateAngle, _mapView.map.mapStatus.inclineAngle, _mapView.map.getCurrentZoomLevel];
    textView.text = text;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - FMKMapViewDelegate
- (void)mapViewDidFinishLoadingMap:(FMKMapView *)mapView {
    NSLog(@"地图加载完成");
}
- (void)mapViewDidFailLoadingMap:(FMKMapView *)mapView withError:(NSError *)error {
    NSLog(@"地图加载失败-%@", error);
}

@end
